package foxmob.mooc;

/**
 * Created by liyusen on 2017/6/10.
 */

import foxmob.mooc.persist.tables.User;
import foxmob.mooc.persist.tables.records.UserRecord;
import org.jooq.Result;
import org.jooq.DSLContext;

public class Test {
    public static void main(String[] args){
        try {

            AppCfg.init();
            DbAccess.init();
            DSLContext dsl = DbAccess.getDsl();
            UserRecord r = dsl.newRecord(User.USER);
            r.setEmail("a@x1x.com");
            r.setUsername("ok2f1ne");
            r.setPasswd("afasdfasdflsdf");
            Integer cnt = r.insert();
            System.out.println("---just insert:----");
            System.out.println(cnt);
            System.out.println("---end----");
            System.out.println("---fetch----");
            // fetchOne is simple
            Result<UserRecord> rs=dsl.selectFrom(User.USER)
                    .where(User.USER.USERNAME.like("o%"))
                    .limit(0, 2).fetch();
            for(UserRecord ru : rs){
                System.out.println("email:"+ru.getEmail());
                ru.setPasswd("no passwd");

                ru.store();

            }
            System.out.println("---end----");




        }catch (Exception e){
            e.printStackTrace();

        }
    }
}
